/**
 * Author: luoqi
 * Created Date: 2025-10-15 22:52:45
 * Last Modified: 2025-10-20 00:57:4
 * Modified By: luoqi at <**@****>
 * Copyright (c) 2025 <*****>
 * Description:
 */

#pragma once

#include <vector>
#include <qshell/qshell.h>

class Commands {
public:
private:
    typedef int (*Callback)(int, char **);
    struct Cmd {
        std::string name;
        Callback cb;
        std::string help;
    };
public:
    inline static std::vector<Cmd> regists;
    static int init()
    {
        static bool inited = false;
        if(inited) {
            return 0;
        }
        for(auto &cmd : regists) {
            QShellObj::obj().cmd_add(cmd.name.c_str(), cmd.cb, cmd.help.c_str());
        }
        inited = true;
        return 0;
    }

    Commands(std::string name, Callback cb, std::string help)
    {
        regists.push_back({ name, cb, help });
    }
};

#define EXPORT_CMD(name, cb, help) \
    static Commands __cmd_##cb(name, cb, help)
